<?php

require_once "Basic.php";

mustBeEmployee();

$page = new Page("Cancelar Reservas do Dia Anterior");

$update = <<<END
update reserva
set cancelada = 1
from Reserva as R
     left join
     Locacao as L
     on R.idReserva = L.efetivacao
where L.efetivacao is null and
      R.previsaoInicio < dateadd(d, -1, CURRENT_TIMESTAMP) and
      R.ativo = 1
END;

$db = new DBUtils();
try {
  $db->connect();
  $db->runQuery($update);
  $db->close();
  $page->addContent("<p>Pronto.</p>");
}
catch(DBError $e) {
  logMessage($e->errors, "Closeday");
  $db->close();
  $page->addContent("<p class='errorMessage'>Falha no banco de dados. O erro foi reportado.</p>");
}

echo $page->getHtml();

